package com.xique.door.project.xyl.controller;

import com.github.pagehelper.PageHelper;
import com.xique.common.core.utils.OrikaUtil;
import com.xique.common.core.utils.SecurityUtils;
import com.xique.common.core.utils.StringUtils;
import com.xique.common.core.web.controller.BaseController;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.common.core.web.page.TableDataInfo;
import com.xique.door.bean.domain.ParkCarMngtype;
import com.xique.door.bean.domain.ParkIn;
import com.xique.door.project.xyl.bean.domain.XylAlarmRecord;
import com.xique.door.project.xyl.bean.request.PersonInOutRequest;
import com.xique.door.project.xyl.bean.vo.ClientCommonVo;
import com.xique.door.project.xyl.bean.vo.SummaryStatisticsVo;
import com.xique.door.project.xyl.bean.vo.XylParkInOutVo;
import com.xique.door.project.xyl.bean.vo.XylPersonInOutVo;
import com.xique.door.project.xyl.service.IxylService;
import com.xique.door.project.xyl.service.IXylAlarmRecordService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: caogq
 * @Date: 2021/12/20 14:22
 * @Description:
 */
@RestController
@RequestMapping("/xyl")
public class XylController extends BaseController {
    @Autowired
    private IxylService xylService;

    @Autowired
    private IXylAlarmRecordService xylAlarmRecordService;

    @GetMapping("/homePageInfo")
    @ApiOperation("西洋楼首页")
    @ResponseBody
    public AjaxResult homePageInfo() {
        return AjaxResult.success(xylService.getHomePageInfo(SecurityUtils.getParkId()));
    }

    @GetMapping("/homePersonInOutRecord")
    @ApiOperation("首页人口流量接口")
    @ResponseBody
    public AjaxResult homePersonInOutRecord() {
        return AjaxResult.success(xylService.selectHomePagePersonInOutRecord(SecurityUtils.getParkId()));
    }

    @GetMapping("/homeParkInOutRecord")
    @ApiOperation("首页车辆记录接口")
    @ResponseBody
    public AjaxResult homeParkInOutRecord() {
        ParkIn parkIn = new ParkIn();
        parkIn.setParkId(SecurityUtils.getParkId());
        return AjaxResult.success(xylService.selectHomePageParkInOutVos(parkIn));
    }
    /**
     * 企业人员统计
     *
     * @return com.xique.common.core.web.domain.AjaxResult
     * @author shd
     * @date 2021/12/21 13:26
     */
    @GetMapping("/companyPersonStatistic")
    @ApiOperation("企业人员统计")
    public AjaxResult companyPersonStatistic() {
        return xylService.companyPersonStatistic(SecurityUtils.getParkId());
    }

    @GetMapping("/buildingInfo")
    @ApiOperation("楼栋信息")
    public AjaxResult buildingInfo() {
        return xylService.buildingInfo(SecurityUtils.getParkId());
    }

    @GetMapping("/personInOutList")
    @ApiOperation("人口流量详情")
    @ResponseBody
    public AjaxResult personInOutList(PersonInOutRequest request) {
        startPage();
        return xylService.selectPagePersonInOutRecordList(request);
    }

    @GetMapping("/parkInOutList")
    @ApiOperation("车辆记录")
    @ResponseBody
    public AjaxResult parkInOutVos(ParkIn parkIn) {
        startPage();
        return xylService.selectPageParkInOutList(parkIn);
    }


    @GetMapping("/park/mngtype")
    @ResponseBody
    @ApiOperation("车辆管理类型列表(搜索条件下拉框)")
    public AjaxResult mngtype()
    {

        ParkCarMngtype parkCarMngtype = new ParkCarMngtype();
        parkCarMngtype.setParkId(SecurityUtils.getParkId());
        List<ParkCarMngtype> list = xylService.selectParkCarMngtypeList(parkCarMngtype);
//        List<ClientCommonVo> vos = OrikaUtil.converts(list, ClientCommonVo.class, Collections.singletonMap("mngTypeLable", "name"));
        List<ClientCommonVo> vos = OrikaUtil.converts(list, ClientCommonVo.class);
        return AjaxResult.success(vos);
    }

    /**
     * 查询西洋楼报警记录列表
     */
    @PostMapping("/alarm/list")
    @ResponseBody
    public TableDataInfo list(@RequestBody XylAlarmRecord xylAlarmRecord)
    {
        PageHelper.startPage(xylAlarmRecord.getPageNum(), xylAlarmRecord.getPageSize());
        List<XylAlarmRecord> list = xylAlarmRecordService.selectXylAlarmRecordList(xylAlarmRecord);
        return getDataTable(list);
    }


    @PostMapping("/alarm/changeStatus")
    @ResponseBody
    public AjaxResult changeStatus(@RequestBody XylAlarmRecord xylAlarmRecord) {
        if (xylAlarmRecord.getId() == null || StringUtils.isEmpty(xylAlarmRecord.getStatus())){
            return AjaxResult.error();
        }
        return toAjax(xylAlarmRecordService.updateXylAlarmRecord(xylAlarmRecord));
    }

    @GetMapping("/alarm/summaryStatistics")
    @ResponseBody
    public AjaxResult summaryStatistics() {
        SummaryStatisticsVo summaryStatistics = xylAlarmRecordService.summaryStatistics();
        return AjaxResult.success(summaryStatistics);
    }
}
